import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["templateId"];

/**
 * service - 消息模板
 * @date: 2018-7-26
 * @version: 1.0.0


 */
import request from 'utils/request';
import { CPAAS_MSG, CPAAS_PLATFORM } from 'utils/config';
import { parseParameters, getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
/**
 * 请求API前缀
 * @type {string}
 */

var prefix = "".concat(CPAAS_MSG, "/v1");
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();
/**
 * 查询消息模板列表数据
 * @async
 * @function search
 * @param {object} params - 查询条件
 * @param {?string} params.templateCode - 消息模板编码
 * @param {?string} params.templateName - 消息模板名称
 * @param {!object} params.page - 分页参数
 * @returns {object} fetch Promise
 */

export function search(_x) {
  return _search.apply(this, arguments);
}
/**
 * 删除消息模板列表数据
 * @async
 * @function deleteItem
 * @param {object} params - 查询条件
 * @returns {object} fetch Promise
 */

function _search() {
  _search = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/message/templates") : "".concat(prefix, "/message/templates"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _search.apply(this, arguments);
}

export function deleteItem(_x2) {
  return _deleteItem.apply(this, arguments);
}
/**
 * 查询消息模板明细
 * @async
 * @function searchDetail
 * @param {object} params - 查询条件
 * @param {?string} params.templateId - 消息模板Id
 * @returns {object} fetch Promise
 */

function _deleteItem() {
  _deleteItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            param = parseParameters(params);
            return _context2.abrupt("return", request("".concat(prefix, "/").concat(organizationId, "/message/templates"), {
              method: 'DELETE',
              body: param
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _deleteItem.apply(this, arguments);
}

export function searchDetail(_x3) {
  return _searchDetail.apply(this, arguments);
}
/**
 * 复制
 * @param {*} params
 */

function _searchDetail() {
  _searchDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/message/templates/").concat(params.templateId) : "".concat(prefix, "/message/templates/").concat(params.templateId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _searchDetail.apply(this, arguments);
}

export function copyDetail(_x4) {
  return _copyDetail.apply(this, arguments);
}
/**
 * 查询消息模板明细模板参数
 * @async
 * @function search
 * @param {object} params - 查询条件
 * @param {!object} params.page - 分页参数
 * @param {?string} params.argName - 参数名称
 * @param {?string} params.templateId - 消息模板Id
 * @returns {object} fetch Promise
 */

function _copyDetail() {
  _copyDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/message/templates/").concat(params.templateId, "/copy") : "".concat(prefix, "/message/templates/").concat(params.templateId, "/copy"), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _copyDetail.apply(this, arguments);
}

export function fetchDetailPara(_x5) {
  return _fetchDetailPara.apply(this, arguments);
}
/**
 * 初始化模板明细模板参数
 * @async
 * @function search
 * @returns {object} fetch Promise
 */

function _fetchDetailPara() {
  _fetchDetailPara = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var templateId, others;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            templateId = params.templateId, others = _objectWithoutProperties(params, _excluded);
            return _context5.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-args/").concat(templateId) : "".concat(CPAAS_MSG, "/v1/template-args/").concat(templateId), {
              method: 'GET',
              query: others
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _fetchDetailPara.apply(this, arguments);
}

export function initPara(_x6) {
  return _initPara.apply(this, arguments);
}
/**
 * 删除模板明细模板参数
 * @async
 * @function search
 * @returns {object} fetch Promise
 */

function _initPara() {
  _initPara = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-args/init") : "".concat(CPAAS_MSG, "/v1/template-args/init"), {
              method: 'POST',
              query: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _initPara.apply(this, arguments);
}

export function deletePara(_x7) {
  return _deletePara.apply(this, arguments);
}
/**
 * 编辑模板明细模板参数
 * @async
 * @function search
 * @returns {object} fetch Promise
 */

function _deletePara() {
  _deletePara = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-args") : "".concat(CPAAS_MSG, "/v1/template-args"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _deletePara.apply(this, arguments);
}

export function editPara(_x8) {
  return _editPara.apply(this, arguments);
}
/**
 * 更新消息模板信息
 * @async
 * @function updateTemplate
 * @param {object} params - 请求参数
 * @param {?string} params.templateCode - 消息模板编码
 * @param {!string} params.templateName - 消息模板名称
 * @param {!string} params.templateContent - 消息模板内容
 * @param {!string} params.templateTitle - 消息模板标题
 * @param {!string} params.templateTypeCode - 消息模板类型
 * @param {!number} params.tenantId - 租户Id
 * @param {!number} params.templateId - 消息模板Id
 * @param {!number} params.enabledFlag - 启用标记
 * @param {?string} params.sqlValue - SQL
 * @returns {object} fetch Promise
 */

function _editPara() {
  _editPara = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-args") : "".concat(CPAAS_MSG, "/v1/template-args"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _editPara.apply(this, arguments);
}

export function updateTemplate(_x9) {
  return _updateTemplate.apply(this, arguments);
}
/**
 * 添加消息模板信息
 * @async
 * @function addTemplate
 * @param {object} params - 请求参数
 * @param {?string} params.templateCode - 消息模板编码
 * @param {!string} params.templateName - 消息模板名称
 * @param {!string} params.templateContent - 消息模板内容
 * @param {!string} params.templateTitle - 消息模板标题
 * @param {!string} params.templateTypeCode - 消息模板类型
 * @param {!number} params.tenantId - 租户Id
 * @param {!number} params.enabledFlag - 启用标记
 * @param {?string} params.sqlValue - SQL
 * @returns {object} fetch Promise
 */

function _updateTemplate() {
  _updateTemplate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/message/templates") : "".concat(prefix, "/message/templates"), {
              method: 'PUT',
              body: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _updateTemplate.apply(this, arguments);
}

export function addTemplate(_x10) {
  return _addTemplate.apply(this, arguments);
}
/**
 * 添加消息模板信息
 * @async
 * @function addTemplate
 * @param {object} params - 请求参数
 * @returns {object} fetch Promise
 */

function _addTemplate() {
  _addTemplate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            return _context10.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/message/templates") : "".concat(prefix, "/message/templates"), {
              method: 'POST',
              body: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _addTemplate.apply(this, arguments);
}

export function searchCategoryCodeTree(_x11) {
  return _searchCategoryCodeTree.apply(this, arguments);
}
/**
 * 查询系统支持的语言数据
 * @async
 * @function queryLanguageData
 * @returns fetch Promise
 */

function _searchCategoryCodeTree() {
  _searchCategoryCodeTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(params) {
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            return _context11.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/lovs/value/tree"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _searchCategoryCodeTree.apply(this, arguments);
}

export function queryLanguageData() {
  return _queryLanguageData.apply(this, arguments);
}

function _queryLanguageData() {
  _queryLanguageData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            return _context12.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/languages/list"), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _queryLanguageData.apply(this, arguments);
}